package com.zts.modules.sys.mapper;

import com.zts.base.data.CrudMapper;
import com.zts.modules.sys.entity.Role;
import com.zts.modules.sys.entity.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.session.RowBounds;
import org.hibernate.validator.constraints.Length;

import java.util.List;
import java.util.Map;

/**
 * Created by lily on 2017/6/13.
 */
public interface RoleMapper extends CrudMapper<Role> {
    @Override
    @SelectProvider(type = RoleSqlProvider.class, method = "get")
    Role get(Long id);

    @Override
    @SelectProvider(type = RoleSqlProvider.class, method = "getByEntity")
    List<Role> getByEntity(Role entity);

    @Override
    @SelectProvider(type = RoleSqlProvider.class, method = "getList")
    List<Role> getList(Role entity, RowBounds rowBounds);

    @Override
    @InsertProvider(type = RoleSqlProvider.class, method = "insert")
    @SelectKey(statement = "SELECT CURRVAL('seq_sys_role_id')", keyProperty = "id", before = false, resultType = Long.class)
    int insert(Role entity);

    @Override
    @UpdateProvider(type = RoleSqlProvider.class, method = "update")
    int update(Role entity);

    @Override
    @DeleteProvider(type = RoleSqlProvider.class, method = "delete")
    int delete(Role entity);

    @SelectProvider(type = RoleSqlProvider.class, method = "isUserd")
    boolean isUserd(Long id);

    @SelectProvider(type = RoleSqlProvider.class, method = "getUsers")
    List<User> getUsers(Long id);

    @SelectProvider(type = RoleSqlProvider.class, method = "getAllUsers")
    List<User> getAllUsers(Long id);

    @DeleteProvider(type = RoleSqlProvider.class, method = "deleteRoleByUserAndGroup")
    int deleteRoleByUserAndGroup(@Param("userId") Long userId, @Param("groupId") Long groupId);

    @DeleteProvider(type = RoleSqlProvider.class, method = "deleteRoleByUsersAndGroup")
    int deleteRoleByUsersAndGroup(@Param("userIds") List<Long> userIds, @Param("groupId") Long groupId);

    @SelectProvider(type = RoleSqlProvider.class, method = "checkGrantExist")
    boolean checkGrantExist(@Param("objectId") Long objectId, @Param("objectType") String objectType,
                            @Param("roleId") Long roleId, @Param("grantType") String grantType);

    @InsertProvider(type = RoleSqlProvider.class, method = "singleGrant")
    @SelectKey(statement = "SELECT CURRVAL('seq_sys_grant_id')", keyProperty = "id", before = false, resultType = Long.class)
    int singleGrant(@Param("objectId") Long objectId, @Param("objectType") String objectType,
                    @Param("roleId") Long roleId, @Param("grantType") String grantType);

    @InsertProvider(type = RoleSqlProvider.class, method = "batchGrant")
    @SelectKey(statement = "SELECT CURRVAL('seq_sys_grant_id')", keyProperty = "id", before = false, resultType = Long.class)
    int batchGrant(@Param("objectId") Long objectId, @Param("objectType") String objectType,
                   @Param("roleIds") List<Long> roleIds, @Param("grantType") String grantType);

    @DeleteProvider(type = RoleSqlProvider.class, method = "singleGrantDelete")
    int singleGrantDelete(@Param("objectId") Long objectId, @Param("objectType") String objectType,
                          @Param("roleId") Long roleId, @Param("grantType") String grantType);

    @DeleteProvider(type = RoleSqlProvider.class, method = "batchGrantDelete")
    int batchGrantDelete(@Param("objectId") Long objectId, @Param("objectType") String objectType,
                         @Param("roleIds") List<Long> roleIds, @Param("grantType") String grantType);

    @SelectProvider(type = RoleSqlProvider.class,method = "getGroupRoles")
    List<Role> getGroupRoles(String groupIds);

    @SelectProvider(type = RoleSqlProvider.class,method = "getUserRoles")
    List<Role> getUserRoles(Long groupId);

    @InsertProvider(type = RoleSqlProvider.class, method = "batchGrantForObjs")
    @SelectKey(statement = "SELECT CURRVAL('seq_sys_grant_id')", keyProperty = "id", before = false, resultType = Long.class)
    int batchGrantForObjs(@Param("objectIds") List<Long> objectIds, @Param("objectType") String objectType,
                          @Param("roleId") Long roleId, @Param("grantType") String grantType);

    @SelectProvider(type = RoleSqlProvider.class, method = "getRolesByUserId")
    List<Role> getRolesByUserId(Long userId);

    @SelectProvider(type = RoleSqlProvider.class, method = "getAllRolesByUserId")
    List<Role> getAllRolesByUserId(Long userId);

    @SelectProvider(type = RoleSqlProvider.class, method = "getRolesByGroupId")
    List<Role> getRolesByGroupId(Long groupId);

    @SelectProvider(type = RoleSqlProvider.class, method = "getAllRolesByGroupId")
    List<Role> getAllRolesByGroupId(Long groupId);
}
